package com.xiaoma.common.ui

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.xiaoma.common.extend.bind


/**
 * author: liangjingbo
 * date: 2022/6/16
 * describe:
 */
abstract class BaseActivity<VB : ViewBinding>(
    inflate: (LayoutInflater) -> VB
) : AppCompatActivity() {

    protected val TAG = "${this.javaClass.simpleName}_XMTag"

    protected val binding by bind(inflate)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val start = System.currentTimeMillis()
        Log.i(TAG, "onCreate() hashCode: ${hashCode()}")
        setContentView(binding.root)
        initView(savedInstanceState)
        initEvent(savedInstanceState)
        Log.i(TAG, "onCreate() spend time: ${System.currentTimeMillis() - start}")
    }



    override fun onStart() {
        super.onStart()
        Log.i(TAG, "onStart() hashCode: ${hashCode()}")
    }

    override fun onRestart() {
        super.onRestart()
        Log.i(TAG, "onRestart() hashCode: ${hashCode()}")
    }

    override fun onResume() {
        super.onResume()
        Log.i(TAG, "onResume() hashCode: ${hashCode()}")
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        Log.i(TAG, "onNewIntent() hashCode: ${hashCode()}")
    }

    override fun onPause() {
        super.onPause()
        Log.i(TAG, "onPause() hashCode: ${hashCode()}")
    }

    override fun onStop() {
        super.onStop()
        Log.i(TAG, "onStop() hashCode: ${hashCode()}")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.i(TAG, "onDestroy() hashCode: ${hashCode()}")
    }


    abstract fun initView(savedInstanceState: Bundle?)

    abstract fun initEvent(savedInstanceState: Bundle?)
}